/**
 * jf project.
 * Copyright 2011 shimizu kenji All Rights Reserved.
 */
package net.lazycode.xfs.local;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.lazycode.xfs.XFile;
import net.lazycode.xfs.XFileSystem;


/**
 * @author shimizu.kenji
 *
 */
public final class LocalFileSystem implements XFileSystem {
    /**
     * {@inheritDoc}
     */
    @Override
    public Collection<XFile> roots() {
        File[] files = File.listRoots();
        List<XFile> list = new ArrayList<XFile>();
        for (File file : files) {
            list.add(file(file.getPath()));
        }
        return list;
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public XFile file(final String location) {
        return new LocalFile(location);
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public boolean available(final String location) {
        try {
            new File(location).getCanonicalPath();
            return true;
        } catch (IOException e) {
            return false;
        }
    }
}
